package com.ljh.account.controller;

import com.github.pagehelper.PageInfo;
import com.ljh.account.dao.BankPartner;
import com.ljh.account.service.BankPartnerService;
import com.ljh.account.utils.Response;
import com.ljh.account.utils.Upload;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/api/admin")
public class BankPartnerController {
    @Autowired
    BankPartnerService bankPartnerService;
//    创建可绑卡的银行
    @PostMapping("/bank")
    public Response bank(@RequestBody BankPartner bankPartner){
        bankPartnerService.addBankPartner(bankPartner);
        return Response.success("银行添加成功！");
    }
//    获取所有的银行列表
    @GetMapping("/bank")
    public Response bank(@RequestParam int page, @RequestParam int size){
        PageInfo allBankPartners = bankPartnerService.getBankPartners(page, size);
        return Response.success(allBankPartners);
    }
//    上传银行卡封面
    @PostMapping("/bank/cover")
    public Response uploadAvt(@RequestParam("file") MultipartFile file) {
        Object data = Upload.uploadImage(file,"cover");
        if(data != null){
            return Response.success(data);
        }else {
            return Response.error("封面上传失败");
        }
    }


}
